#include <iostream>
#include <vector>

using namespace std;

class Solution
{
public:
    int removeElement(vector<int>& nums, int val)
    {
        for(auto it = nums.begin(); it != nums.end(); it++)
        {
            if (*it == val)
            {
                nums.erase(it);
                it--;
            }
        }
        return nums.size();
    }
};

int main()
{
    Solution s;
    vector<int> nums = {3, 2, 2, 3};
    int val = 3;
    int size = s.removeElement(nums, val);
    cout << "New size: " << size << endl; // 输出 New size: 2

    cout << "Array content: ";
    for (int i = 0; i < size; i++) {
        cout << nums[i] << " "; // 输出 Array content: 2 2 
    }
    cout << endl;

    // 测试一个连续移除的例子
    vector<int> nums2 = {0, 1, 2, 2, 3, 0, 4, 2};
    int val2 = 2;
    int size2 = s.removeElement(nums2, val2);
    cout << "\nNew size: " << size2 << endl; // 输出 New size: 5
    cout << "Array content: ";
    for (int i = 0; i < size2; i++) {
        cout << nums2[i] << " "; // 输出 Array content: 0 1 3 0 4
    }
    cout << endl;
}